package common.propAward.view
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.greensock.TweenLite;
	import com.liangzhong.constants.ShareConst;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.ShareEvent;
	import com.liangzhong.model.AppData;
	//import com.liangzhong.model.shop.GoodVo;
	
	import common.IGetPropView;
	import common.item.IconItem;
	
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	import lz.controls.core.UIComponent;
	import lz.controls.managers.AnimationManager;

	/**
	 *获得奖励物品 
	 * @author lake
	 * 
	 */	
	public class GetPropView extends UIComponent implements IGetPropView
	{
		/**
		 * 分享按钮
		 */		
		private var shareBtn 	:SimpleButton;
		/**
		 * 确认按钮
		 */		
		private var sureBtn	:SimpleButton;
		/**
		 *物品容器 
		 */		
		private var awardContainer :MovieClip;
		
		public function GetPropView()
		{
			super();
		}
		/**
		 *获取设置数据 
		 * @param value
		 */		
		public function set data(value:*):void
		{
			var pids :Array = value;
			if(_symbolSkin == null)
			{
				return;
			}
			_symbolSkin.gotoAndPlay(1);
			var iconItem :IconItem;
			var bitmapData :BitmapData;
			/*var goodVo :GoodVo;
			for each(var pid :int in pids)
			{
				goodVo = AppData.getInstance().shopDataManager.getGooodVoById(pid);
				if(goodVo)
				{
					bitmapData = goodVo.bitmapData;
					iconItem = new IconItem();
					iconItem.data = bitmapData;
					iconItem.tips = goodVo.name;
					iconItem.x = awardContainer.width;
					if(awardContainer.numChildren > 0)
					{
						iconItem.x += 10;
					}
					awardContainer.addChild(iconItem);
				}
			}*/
			TweenLite.delayedCall(0.2,function():void{awardContainer.alpha = 1;});
			awardContainer.x = (GlobalDef.StageWidth - awardContainer.width)/2;
		}
		public function get data():*
		{
			return null;
		}
		/**
		 * 初始化
		 * @param view
		 * 
		 */		
		public function initUI(view:Object=null):void
		{
			_symbolSkin = Reflection.createInstance("com.lz.res.GetPropItemViewSkin");
			if(_symbolSkin == null)
			{
				return;
			}
			_symbolSkin.y = 150;
			this.addChild(_symbolSkin);
			_symbolSkin.gotoAndStop(1);
			shareBtn = _symbolSkin.shareBtn;
			sureBtn = _symbolSkin.sureBtn;
			awardContainer = _symbolSkin.awardContainer;
			addEvtListener();
		}
		/**
		 * 
		 * 添加事件
		 */		
		public function addEvtListener():void
		{
			sureBtn.addEventListener(MouseEvent.CLICK,onCloseHandler);
			shareBtn.addEventListener(MouseEvent.CLICK,onShareHandler)
		}
		/**
		 *关闭 
		 * @param e
		 * 
		 */		
		private function onCloseHandler(e :MouseEvent):void
		{
			var aDispt :DisplayObject;
			var gPoint :Point ;
			while(awardContainer.numChildren > 0)
			{
				aDispt = awardContainer.getChildAt(0);
				gPoint = aDispt.localToGlobal(new Point(0,0));
				//AnimationManager.moveToBag(gPoint,aDispt,.5);
			}
			destroyView();
		}
		/**
		 *分享捕获 
		 * @param e
		 * 
		 */		
		private function onShareHandler(e :MouseEvent):void
		{
			//destroyView();
			shareBtn.mouseEnabled = false;
			//share
			var shareParam :Object = {};
			shareParam.type = ShareConst.Prop_Get;
			AppEventDispatcher.getInstance().dispatchEvent(new ShareEvent(ShareEvent.SHARE_SAY,shareParam));
		}
		/**
		 * 删除事件
		 * 
		 */		
		public function removeEvtListener():void
		{
			sureBtn.removeEventListener(MouseEvent.CLICK,onCloseHandler);
			shareBtn.removeEventListener(MouseEvent.CLICK,onShareHandler)
		}
		/**
		 * 销毁
		 */		
		public function destroyView():void
		{
			AnimationManager.remove();
			removeEvtListener();
			DisplayObjectUtil.removeAllChildren(awardContainer);
			if(this.parent)this.parent.removeChild(this);
		}
	}
}